/**
 * editor_plugin_src.js
 *
 * Copyright 2013, Imagine.lt studio
 * Released under LGPL License.
 *
 */

(function() {
	tinymce.create('tinymce.plugins.AdvancedImagePlugin', {
		init : function(ed, url) {
			// Register commands
			ed.addCommand('mceAdvImage', function() {
				// Internal image object like a flash placeholder
				if (ed.dom.getAttrib(ed.selection.getNode(), 'class', '').indexOf('mceItem') != -1)
					return;
					
				var tvs_parent = ed.getParam("tvs_parent");
				var tvs_tpl_parent_name = ed.getParam("tvs_tpl_parent_name");
				var tvs_field = ed.getParam("tvs_field");
				
				ed.windowManager.open({
					file : ed.documentBaseURI.getURI(url)+'index.php?admin=1&inspic=1&parent='+tvs_parent+'&tpl_parent_name='+tvs_tpl_parent_name+'&field='+tvs_field,
					//file : url + '/image.htm',
					width : 620 + parseInt(ed.getLang('advimage.delta_width', 0)),
					height : 540 + parseInt(ed.getLang('advimage.delta_height', 0)),
					inline : 1
				}, {
					plugin_url : url
				});
			});

			// Register buttons
			ed.addButton('image', {
				title : 'advimage.image_desc',
				cmd : 'mceAdvImage'
			});
		},

		getInfo : function() {
			return {
				longname : 'Advanced image (modifed)',
				author : 'Imagine Team',
				authorurl : 'http://www.imagine.lt',
				infourl : 'http://www.imagine.lt',
				version : tinymce.majorVersion + "." + tinymce.minorVersion
			};
		}
	});

	// Register plugin
	tinymce.PluginManager.add('advimage', tinymce.plugins.AdvancedImagePlugin);
})();